package com.pronhub.luowowo.mgrsite.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.pronhub.luowowo.article.domain.TravelContent;
import com.pronhub.luowowo.article.query.TravelQuery;
import com.pronhub.luowowo.article.service.ITravelService;
import com.pronhub.luowowo.util.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("travel")
public class TravelController {
    //查出所有的游记 还是分页的那种

    @Reference
    private ITravelService travelService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo")TravelQuery qo){
        //查的文章是公开通过审核的
        qo.setIsPublic(true);//公开
        if (qo.getState()==null){
            int[] sta={1,3};
            qo.setState(sta);
        }
        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "travel/list";
    }

    //
    @RequestMapping("getContentById")
    @ResponseBody
    public TravelContent getContentById(Long id){
        TravelContent content = travelService.getContent(id);
        return content;
    }
    /**
     * 发布
     */
    @RequestMapping("update")
    public Object update(Long id,int state){
        travelService.changeTheStateById(id,state);
        return AjaxResult.SUCCESS;
    }

}
